package com.ddd.mill.infrastructure.persistent.repository;

public interface Repository<EntityType, IDType> {
    EntityType load(IDType id);

    IDType save(EntityType entity);

    default Boolean isExisted(IDType id) {
        return this.load(id) != null;
    }

    default EntityType mustBeExisted(IDType id) throws Exception {
        EntityType entity = this.load(id);
        if (entity == null) {
            throw new Exception();
        }

        return entity;
    }
}
